package com.dx.controller;

import com.dx.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/interface")
@RequiredArgsConstructor
@Api(tags = "晓搭模拟测试接口")
public class XiaodaController {


    /**
     * 测试接口
     */
    @PostMapping("/test")
    @ApiOperation("晓搭接口模拟，用于测试")
    public R<?> testInterface(@RequestBody R<?> requestBody, @RequestHeader String token, @RequestHeader String type, Long id) {
        //模拟接口的成功和失败情况
        //产生一个0-2的随机数
        int randomNumber = (int) (Math.random() * 3);
        System.out.println("randomNumber = " + randomNumber);
        if (randomNumber<2) {
            return R.fail("晓搭接口执行失败");
//            throw new RuntimeException("接口调用失败");
        }
        System.out.println("开始所配置接口的调用");
        System.out.println("请求体为"+requestBody);
        System.out.println("请求头信息如下");
        System.out.println("token为" + token);
        System.out.println("type = " + type);
        System.out.println("请求参数信息如下");
        System.out.println("id = " + id);
        System.out.println("接口调用成功");
        return R.success("晓搭接口执行成功");
    }


}
